﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

using FRL.DebtChased.Website;
using FRL.DebtChased.Repository;

namespace WebApplication
{

	public class Global : System.Web.HttpApplication
	{

		protected void Application_Start(object sender, EventArgs e)
		{

			// Load data from the entities
			using (DebtChasedEntities ent = new DebtChasedEntities())
			{

				// Cache the countries
				CountryCodes.LoadUp(ent);

			}

			// settup the application-scope singleton object
			MyApplication.Startup();

			// Chop the home from the site path
			SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(HideRootNode);

		}

		protected void Session_Start(object sender, EventArgs e)
		{

		}

		protected void Application_BeginRequest(object sender, EventArgs e)
		{

		}

		protected void Application_AuthenticateRequest(object sender, EventArgs e)
		{

		}

		protected void Application_Error(object sender, EventArgs e)
		{

		}

		protected void Session_End(object sender, EventArgs e)
		{

		}

		protected void Application_End(object sender, EventArgs e)
		{

		}

		static SiteMapNode HideRootNode(Object sender, SiteMapResolveEventArgs e)
		{
			//
			// Hide the root node from SiteMapPath controls by cloning the site
			// map from the current node up to the node below the root node and
			// setting that node's ParentNode property to null.
			//

			SiteMapNode current = null;
			if (SiteMap.CurrentNode != null)
			{
				SiteMapNode node = SiteMap.CurrentNode.Clone();
				current = node;
				SiteMapNode root = SiteMap.RootNode;

				if (current != root) // Just in case the current node *is* the root node!
				{
					while (node.ParentNode != root)
					{
						node.ParentNode = node.ParentNode.Clone();
						node = node.ParentNode;
					}
					node.ParentNode = null;
				}
			}
			return current;
		}


	}
}